﻿using BuddHa.Common.JsonOpex;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace BuddHa.Common
{
    public class ConstProperty
    {
        public static JsonSerializerOptions CreateDefaultJsonSerializerOptions(bool dateTimeConverter = false)
        {
            var jsonSerializerOptions = new JsonSerializerOptions()
            {
                Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
                //反序列化过程中属性名称不区分大小写的比较
                PropertyNameCaseInsensitive = true,
                //IgnoreNullValues = true 已过时
                DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
                //修改时间的序列化方式
            };
            if (dateTimeConverter)
            {
                jsonSerializerOptions.Converters.Add(new DateTimeConverter());
            }
            return jsonSerializerOptions;
        }
    }
}
